package com.wsm.common.controller;

import com.wsm.common.annotation.DuplicateSubmitToken;
import com.wsm.common.annotation.OperateLog;
import com.wsm.common.utils.PageUtils;
import com.wsm.common.utils.Result;
import com.wsm.common.business.ModelBusiness;
import com.wsm.common.domain.ModelDO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * 系统模板
 *
 * @author wangshimin
 * @email wangshiminhome@foxmail.com
 * @date 2020-02-20 10:21:26
 * @description : 系统模板
 */
@Api(tags = "系统模板")
@Controller
@RequestMapping("/common/model")
public class ModelController {
	@Autowired
	private ModelBusiness modelBusiness;
	
	@GetMapping()
	@ApiOperation(value = "跳转展示界面")
	@RequiresPermissions("common:model:look")
	String Model(){
	    return "common/model/model";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@ApiOperation(value = "获取集合列表")
	@RequiresPermissions("common:model:look")
	@DuplicateSubmitToken(save = true, expire = 2, time = TimeUnit.MINUTES)
	public Result<PageUtils> list(@RequestParam Map<String, Object> params){
			params.put("delFlag",1);
			return modelBusiness.list(params);
	}

	@ResponseBody
	@GetMapping("/adminList")
	@ApiOperation(value = "获取集合列表")
	@RequiresPermissions("common:model:adminLook")
	@DuplicateSubmitToken(save = true, expire = 2, time = TimeUnit.MINUTES)
	public Result<PageUtils> adminList(@RequestParam Map<String, Object> params){
		return modelBusiness.list(params);
	}
	
	@GetMapping("/add")
	@ApiOperation(value = "跳转增加界面")
	@RequiresPermissions("common:model:add")
	String add(){
	    return "common/model/add";
	}

	@GetMapping("/edit/{id}")
	@ApiOperation(value = "跳转修改界面")
	@RequiresPermissions("common:model:edit")
	String edit(@PathVariable("id") Long id,Model model){
		ModelDO models = modelBusiness.get(id);
		model.addAttribute("model", models);
	    return "common/model/edit";
	}
	
	/**
	 * 保存
	 */
	@OperateLog("增加系统模板")
	@ResponseBody
	@PostMapping("/save")
	@ApiOperation(value = "增加")
	@DuplicateSubmitToken(save = true, expire = 2, time = TimeUnit.MINUTES)
	@RequiresPermissions("common:model:add")
	public Result save( ModelDO model){
		return modelBusiness.save(model);
	}

	/**
	 * 修改
	 */
	@OperateLog("修改系统模板")
	@ResponseBody
	@RequestMapping("/update")
	@ApiOperation(value = "修改")
	@DuplicateSubmitToken(save = true, expire = 2, time = TimeUnit.MINUTES)
	@RequiresPermissions("common:model:edit")
	public Result update( ModelDO model){
		return modelBusiness.update(model);
	}
	
	/**
	 * 删除
	 */
	@OperateLog("删除系统模板")
	@ResponseBody
	@PostMapping( "/remove")
	@ApiOperation(value = "删除")
	@DuplicateSubmitToken(save = true, expire = 2, time = TimeUnit.MINUTES)
	@RequiresPermissions("common:model:remove")
	public Result remove( Long id){
		return modelBusiness.remove(id);
	}
	
	/**
	 * 删除
	 */
	@OperateLog("批量删除系统模板")
	@ResponseBody
	@PostMapping( "/batchRemove")
	@ApiOperation(value = "批量删除")
	@DuplicateSubmitToken(save = true, expire = 2, time = TimeUnit.MINUTES)
	@RequiresPermissions("common:model:batchRemove")
	public Result remove(@RequestParam("ids[]") List<Long> ids){
		return modelBusiness.batchRemove(ids);
	}

	/**
	 * 删除
	 */
	@OperateLog("伪删除系统模板")
	@ResponseBody
	@PostMapping( "/removeDel")
	@ApiOperation(value = "伪删除")
	@DuplicateSubmitToken(save = true, expire = 2, time = TimeUnit.MINUTES)
	@RequiresPermissions("common:model:removeDel")
	public Result removeDel(Long id){
		return modelBusiness.removeOrDel(id);
	}

	/**
     * 删除
     */
	@OperateLog("批量伪删除系统模板")
	@ResponseBody
	@PostMapping( "/batchRemoveDel")
	@ApiOperation(value = "批量伪删除")
	@DuplicateSubmitToken(save = true, expire = 2, time = TimeUnit.MINUTES)
	@RequiresPermissions("common:model:batchRemoveDel")
	public Result batchRemoveDel(@RequestParam("ids[]")Long[] ids){
		return modelBusiness.batchRemoveOrDel(ids);
	}

	/**
	 * 伪删除改为未删除
	 */
	@OperateLog("伪删除改为未删除系统模板")
	@ResponseBody
	@PostMapping( "/addOrDel")
	@ApiOperation(value = "伪删除改为未删")
	@DuplicateSubmitToken(save = true, expire = 2, time = TimeUnit.MINUTES)
	@RequiresPermissions("common:model:addOrDel")
	public Result addOrDel(Long id){
		return modelBusiness.addOrDel(id);
	}

	/**
     * 批量伪删除改为未删除
     */
	@OperateLog("批量伪删除改为未删除系统模板")
	@ResponseBody
	@PostMapping( "/batchAddOrDel")
	@ApiOperation(value = "批量伪删除改为未删除")
	@DuplicateSubmitToken(save = true, expire = 2, time = TimeUnit.MINUTES)
	@RequiresPermissions("common:model:batchAddOrDel")
	public Result batchAddOrDel(@RequestParam("ids[]")Long[] ids){
		return modelBusiness.batchAddOrDel(ids);
	}

	/**
	 * 修改为不可用状态
	 */
	@OperateLog("修改为不可用状态态系统模板")
	@ResponseBody
	@PostMapping( "/removeUseFlag")
	@ApiOperation(value = "修改为不可用状态")
	@RequiresPermissions("common:model:change")
	@DuplicateSubmitToken(save = true, expire = 2, time = TimeUnit.MINUTES)
	public Result removeUseFlag(Long id){
		return modelBusiness.removeUseFlag(id);
	}
	/**
	 * 修改为可用状态
	 */
	@OperateLog("修改为可用状态系统模板")
	@ResponseBody
	@PostMapping( "/addUseFlag")
	@ApiOperation(value = "修改为可用状态")
	@RequiresPermissions("common:model:change")
	@DuplicateSubmitToken(save = true, expire = 2, time = TimeUnit.MINUTES)
	public Result addUseFlag(Long id){
		return modelBusiness.addUseFlag(id);
	}

}
